//package com.example.tsbs.entity;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.example.tsbs.mapper.TaskMapper;
//import com.example.tsbs.util.FileUtil;
//import com.example.tsbs.util.HttpRequest;
//import com.example.tsbs.util.UseUtil;
//import lombok.SneakyThrows;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.ObjectUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//
//import java.io.IOException;
//
//@Slf4j
//public class TestThread implements Runnable{
//
//    @Autowired
//    private TaskMapper taskMapper;
//
//    /**
//     * 线程私有属性，创建线程时创建
//     */
//    private Integer i;
//    private Integer length;
//    private Integer size;
//    private Integer success;
//    private String taskType;
//    private String parameter;
//    private String message;
//    private Task task;
//
//    public void setMessage(String message) {
//        this.message = message;
//    }
//    public String getMessage() {
//        return this.message;
//    }
//
//    public TestThread(Integer i,Integer length,String taskType,String parameter,String message,Task task) {
//        this.i = i;
//        this.length = length;
//        this.taskType = taskType;
//        this.parameter = parameter;
//        this.message = message;
//        this.task = task;
//    }
//
//    @Override
//    public String toString() {
//        return getMessage();
//    }
//
//    @SneakyThrows
//    @Override
//    public void run() {
//
//        log.info("第"+i+"个线程开始执行!"+String.valueOf(length));
//        message = runStorage(task.getType(), task.getParameter(), length);
////        message = "执行可执行文件";
//        // 判断线程池中的所有线程执行完毕
//        if (ObjectUtils.isNotEmpty(message)) {
//            log.info("第"+i+"个线程执行完毕!"+"执行结果："+message);
//        }
//        setMessage(message);
//
//    }
//    public void setHttpMessage(String url) {
//        //线程全部完成则通知
////        String url = "http://127.0.0.1:3910/api/task/httpApi?id=" + task.getId();
//        //更新任务进度
//        task.setProgress(1.0);
//        if (success >= 4) {
//            task.setResponse("{\"log\":" + "\"" + "成功" + "\"}");
//        }
//        taskMapper.updating(task, task.getId());
//        log.info("线程全部完成!");
//        HttpRequest.getRequest(url);
//    }
//
//    public String runStorage(String taskType, String parameter, Integer length) throws IOException {
//        String result = "";
////            if (taskType == "MZ" || taskType == "mz") {
////                JSONObject json = JSON.parseObject(parameter);
////                String input_files = json.getString("input_files");
////                String model_path = json.getString("model_path");
////                //执行模型整备任务
////                result = FileUtil.CopyFolder(input_files,model_path);
////                //获取频域结果文件，调用可执行程序TS
////
////            }
////            else if (taskType == "CZ" || taskType == "cz") {
////                JSONObject json = JSON.parseObject(parameter);
////                String cad_path = json.getString("cad_path");
////                String material_path = json.getString("material_path");
////                //执行材料整备任务
////                result = FileUtil.CopyFolder(cad_path,material_path);
////                //获取频域结果文件，调用可执行程序
////                result = "仅存储文件";
////            }
////            else
//        if (taskType == "BP" || taskType == "bp") {
//            //板块元频域任务BP
//            JSONObject json = JSON.parseObject(parameter);
//            String inp_path = json.getString("inp_path");
//            String result_path = json.getString("result_path");
//            //执行板块元频域任务
//            //获取频域结果文件，调用可执行程序
//            String datFileName = "/test.dat";
//            UseUtil.callPythonAndCopy("/root/gltf/gltf_interface.py", parameter, result_path);
//            log.info("调用可执行程序");
//            String messgae = "可执行程序返回的结果数据";
//            boolean flag = FileUtil.writeStringToFile(messgae, result_path + "/test.dat");
//            if (flag == true) {
//                result = FileUtil.CopyFolder(inp_path, result_path);
//            } else {
//                log.info(datFileName.substring(1)+"文件生成失败");
//                result = datFileName.substring(1) + "文件生成失败";
//            }
//
//        } else if (taskType == "BS" || taskType == "bs") {
//            //板块元时域任务BS
//            JSONObject json = JSON.parseObject(parameter);
//            String inp_path = json.getString("inp_path");
//            String path = json.getString("path");
//            //执行板块元时域任务
//            //获取频域结果文件，调用可执行程序TS
//            result = "仅存储文件";
//            String datFileName = "/test.dat";
//            log.info("调用可执行程序");
//            String messgae = "可执行程序返回的结果数据";
//            boolean flag = FileUtil.writeStringToFile(messgae, path + datFileName);
//            if (flag == true) {
//                result = FileUtil.CopyFolder(inp_path, path);
//            } else {
//                log.info(datFileName.substring(1)+"文件生成失败");
//                result = datFileName.substring(1) + "文件生成失败";
//            }
//        }
////            else if (taskType == "JP" || taskType == "jp") {
////                JSONObject json = JSON.parseObject(parameter);
////                String part_path = json.getString("part_path");
////                String path = json.getString("path");
////                //执行解析触频域任务
////                result = FileUtil.CopyFolder(part_path,path);
////                //获取频域结果文件，调用可执行程序TS
////                result = "仅存储文件";
////            }
////            else if (taskType == "XZ" || taskType == "xz") {
////                JSONObject json = JSON.parseObject(parameter);
////                String path = json.getString("path");
////                //执行效能分析-主动任务 //获取频域结果文件，调用可执行程序TS
////                result = "未完成";
////
////            }
////            else if (taskType == "XB" || taskType == "xb") {
////                JSONObject json = JSON.parseObject(parameter);
////                String path = json.getString("path");
////                //执行效能分析-被动任务 //获取频域结果文件，调用可执行程序TS
////                result = "未完成";
////            }
//        else {
//            //log.info("任务类型为"+taskType+",暂无法进行计算");
//            result = "任务类型为"+taskType+"暂无法进行计算";
//        }
//        return result;
//    }
//
//}
